package org.brisling.ethic.queryService;

import java.util.LinkedHashMap;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.brisling.base.domain.ListDomain;
import org.brisling.base.service.AbstractBaseQueryService;
import org.brisling.common.ConstSysParam;
import org.brisling.common.util.JsonUtil;
import org.brisling.ethic.domain.EvaluateSubDomain;
import org.brisling.ethic.domain.VOEthicEvaluateSub;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequestMapping("/ethicEvaluateSub/query")
public class QueryEthicEvaluateSubService extends AbstractBaseQueryService<EvaluateSubDomain>{
	
	
	
//	@Autowired
//	private ShiroSecurityService shiroSecurityService;	
//	@Autowired
//	private QueryDictionaryService dicService;
	@Autowired
	private QueryDicSubjectService qryDicSubjectService;
	
//	private String deptid_code = "depart_code";
	
	public QueryEthicEvaluateSubService(){
		this.moduleName = ConstSysParam.MODULE_ETHIC_EVALUATE_SUB;
		this.subSystem = ConstSysParam.SUBSYSTEM_ETHIC;
		this.tableName = moduleName;
		this.clazz = EvaluateSubDomain.class;
		
		typeMap = this.getTypeMap(clazz);
		
		orderMap = new LinkedHashMap<String,String>();
		
		orderMap.put("bizno",null);		
		
	}
	
	@PersistenceContext(unitName=ConstSysParam.SUBSYSTEM_SYSMAN)
	@Autowired
	protected void setEntityManager(EntityManager entityManager){
		this.entityManager = entityManager;		
	}
	
	@RequestMapping("/mainPage.action")
	public ModelAndView getMainPage(){
		return this.getBizMainPage();
	}
	
	/* (non-Javadoc)
	 * @see org.brisling.service.sysman.DepartmentServiceInf#getEditPage()
	 */
	@RequestMapping("/editPage.action")
	public ModelAndView getEditPage(){
		return this.getBizEditPage();
	}
	
	
	@RequestMapping("/getSubListDomainByMainId.action")
	public Object getSubListDomainByMainId(@RequestParam(required=false) Long mainid){		
		
		if(mainid!=null && mainid>0){			 
			EvaluateSubDomain domain = this.getOneByIdentify("typeId",mainid.toString());
			if(domain!=null && domain.getId()!=null){	
				List<Object> sublist = JsonUtil.bodyToList(domain.getSublist(), VOEthicEvaluateSub.class);
				return sublist;
			}
		}
				
		return initSubList();
	}
	
	private ListDomain<Object> initSubList(){
		return qryDicSubjectService.getInitListDomain();
	}
	
	/**
	 * 根据用户id查找用户信息
	 * @param id	用户id
	 * @return 用户信息记录 
	 */
	@RequestMapping("/getOne.action")
	public EvaluateSubDomain getOne(@RequestParam(value="id",required=false) Long id){
		return super.getOne(id);
	}
	
	
	
	/**
	 * 根据用户唯一编码查找用户信息
	 * @param identify	用户唯一编码
	 * @return 用户信息记录
	 */
	@RequestMapping("/getOneByIdentify.action")
	public EvaluateSubDomain getOneByIdentify(@RequestParam(value="field",required=false) String field,@RequestParam(value="fieldVal",required=false) String fieldVal){	
		return super.getOneByIdentify(field,fieldVal);
	}
	
	
}
